package values.quest
{
import core.Language;

import flash.utils.Dictionary;

import values.common.BonusValue;
import values.common.IconValue;

/**
 * QuestTemplateValue
 * @author jliang
 * 
 */
public class QuestTemplateValue
{
	public var group:QuestGroupTemplateValue;
	
	[Data(type="field", mapping="@key")]
	public var key:String;
	
	[Data(type="field", mapping="@name")]
	public var baseName:String;
	
	public function get name():String
	{
		return Language.getText(baseName);
	}
	
	[Data(type="field", mapping="@desc")]
	public var baseDesc:String;
	
	public function get desc():String
	{
		return Language.getText(baseDesc);
	}
	
	private var _icons:Dictionary;
	
	public function get icons():Dictionary
	{
		return _icons;
	}
	
	[Data(type="mapping", 
		  mapping="icons.icon", 
		  ref="values.common.IconValue",
		  way="one_to_more",
		  object="flash.utils.Dictionary",
          key="@key")]
	public function set icons(value:Dictionary):void
	{
		_icons = value;
	}
	
	public function getIconPathByKey(key:String):String
	{
		if(_icons[key])
		{
			return IconValue(_icons[key]).url;
		}		
		return null;
	}
	
	private var _bonus:BonusValue = new BonusValue();
	
	public function get bonus():BonusValue
	{
		return _bonus;
	}
	
	[Data(type="mapping", 
		   mapping="bonus", 
		   ref="values.common.BonusValue",
		   way="own")]
	public function set bonus(value:BonusValue):void
	{
		_bonus = value;
	}
	
	private var _goals:Array;
	
	public function get goals():Array
	{
		return _goals;
	}
	
	[Data(type="mapping", 
		  mapping="goals.goal", 
		  ref="values.quest.QuestGoalTemplateValue",
		  way="one_to_more")]
	public function set goals(value:Array):void
	{
		_goals = value;
	}
	
	public function getGoalTemplate(index:int):QuestGoalTemplateValue
	{
		return goals[index];
	}
	
	private var _events:Dictionary;
	
	public function get events():Dictionary
	{
		return _events;
	}
	
	[Data(type="mapping", 
		  mapping="events.event", 
		  ref="values.quest.QuestEventValue",
		  way="one_to_more",
		  object="flash.utils.Dictionary",
          key="@type")]
	public function set events(value:Dictionary):void
	{
		_events = value;
	}
	
	public function getEventByType(type:String):QuestEventValue
	{
		if(_events[type])
		{
			return QuestEventValue(_events[type]);
		}		
		return null;
	}
	
	[Data(type="field", mapping="ui_assets.asset")]
	public var uiAssets:*;
	
	public function getUIAssetDefByKey(key:String):XMLList
	{
		return uiAssets.(@key == key);
	}
}
}




